package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.AccountFlowListBean;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.clientCenter.queryBean.UserChangeQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.PrintInterfaceImpl;
import org.apache.commons.beanutils.BeanUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * 梁光春-用户账户流水打印
 */
public class AccountFlowListPrint implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			UserChangeQueryBean bean = JsonUtils.objectToPojo(req.getData(), UserChangeQueryBean.class);
			// 校验为空判断,待确定
			// TODO Auto-generated method stub
			UserInfoMapper mapper = factory.getMapper(UserInfoMapper.class);
			bean.setPageCount(999999);
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			List<AccountFlowListBean> list = mapper.accountFlowList(bean);
			
			MessageBean<String> msg = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", String.class);
			ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>();
			for (AccountFlowListBean vo : list) {
				Map<String, String> m =  new HashMap<String, String>();
				m = BeanUtils.describe(vo);
				m.remove("class");
				data.add((HashMap<String, String>) m);
			}
			//设置打印数据
			String key = PrintInterfaceImpl.setPrintData(data);
			//返回key
			msg.setData(key);
			return msg;
		} catch (Exception e) {
			logger.error("用户账户流水打印查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "打印失败", null);
		}
	}

}
